package com.lz.football.module.compete
{
	import com.common.stdlib.ArrayUtil;
	import com.common.utils.Reflection;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.compete.item.InlandRankItem;
	
	import common.BaseView.BaseView;
	
	import flash.display.MovieClip;
	
	import lz.controls.nick.PagePanel;
	
	public class InlandRankView extends BaseView
	{
		/**
		 *当前排名容器  
		 */
		private var currContain:MovieClip;
		/**
		 *上轮排名容器 
		 */
		private var upContain:MovieClip;
		/**
		 *上一页 
		 */
		private var _upPage:PagePanel;
		/**
		 *当前页 
		 */
		private var _currPage:PagePanel;
		/**
		 *当前的排名  
		 */
		private var _currItemVec:Vector.<InlandRankItem>;
		private var _preItemVec:Vector.<InlandRankItem>;
		
		public function InlandRankView()
		{
			super();
		}
		/**
		 * 
		 * @param view
		 * 
		 */
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.compete.inlandRankView");
			this.addChild(symbolSkin);
			symbolSkin.cacheAsBitmap = true;
			_windowBg = symbolSkin.bg
			isDrag = true;
			isCloseBtn = true;
			_viewHeight = symbolSkin.height;
			_viewWidth  = symbolSkin.width;
			currContain = symbolSkin.currContain;
			upContain = symbolSkin.upContain;
			moveClose(_viewWidth - 30,5);
			onResizeHandler();
			addEvtListener();
			initCurrentItem();
			initUpItem();
			initPage();
		}
		/**
		 *当前排名  
		 * 
		 */
		private function initCurrentItem():void
		{
			_currItemVec = new Vector.<InlandRankItem>();
			var item:InlandRankItem;
			for(var i:int = 0;i < 10;i++)
			{
				item = new InlandRankItem();
				item.initUI(2);
				item.y = item.height * i;
				currContain.addChild(item);
				_currItemVec.push(item);
			}
				
		}
		/**
		 *上轮排名  
		 * 
		 */
		private function initUpItem():void
		{
			_preItemVec = new Vector.<InlandRankItem>();
			var item:InlandRankItem;
			for(var i:int = 0;i < 10;i++)
			{
				item = new InlandRankItem();
				item.initUI(1);
				item.y = item.height * i;
				upContain.addChild(item);
				_preItemVec.push(item);
			}
		}
		/**
		 * 
		 * 
		 */
		private function initPage():void		
		{
			_upPage = new PagePanel();
			_upPage.initUI("com.lz.commonUI.turnPage_white");
			this.addChild(_upPage);
			_upPage.x = 466;
			_upPage.y = 358;
			_upPage.callBack = selectUPPage;
			_currPage = new PagePanel();
			_currPage.initUI("com.lz.commonUI.turnPage_white");
			this.addChild(_currPage);
			_currPage.x = 162;
			_currPage.y = 358;
			_currPage.callBack = selectCurrentPage;
		}
		/**
		 *选择了上一前页 
		 * @param $type
		 * 
		 */
		private function selectUPPage($type:String = ""):void
		{
			while(upContain.numChildren)
			{
				upContain.removeChildAt(0);
			}
			var arr:Array = AppData.getInstance().competeDataManager.previousList;
			var temp:Array = ArrayUtil.getPageSizeDatas(_upPage.min,10,arr);
			var len:int = temp.length> _preItemVec.length?_preItemVec.length:temp.length;
			for(var i:int =0 ;i < len;i++)
			{
				_preItemVec[i].setUpData(temp[i]);
				upContain.addChild(_preItemVec[i]);
			}
			
			
		}
		/**
		 *选择了当前页 
		 * @param $type
		 * 
		 */
		private function selectCurrentPage($type:String = ""):void
		{
			while(currContain.numChildren)
			{
				currContain.removeChildAt(0);
			}
			//AppData.getInstance().competeDataManager.rerankCurrent();
			var arr:Array = AppData.getInstance().competeDataManager.currList;
			var temp:Array = ArrayUtil.getPageSizeDatas(_currPage.min,10,arr);
			var len:int = temp.length> _currItemVec.length?_currItemVec.length:temp.length;
			for(var i:int =0 ;i < len;i++)
			{
				_currItemVec[i].setCurrentData(temp[i]);
				currContain.addChild(_currItemVec[i]);
			}
		}
		
		
		/**
		 *更新数据 
		 * 
		 */
		public function upData():void
		{
			_upPage.min = 1;
			_upPage.max = Math.ceil(AppData.getInstance().competeDataManager.previousList.length/ 10);
			_currPage.min = 1;
			_currPage.max = Math.ceil(AppData.getInstance().competeDataManager.currList.length/ 10);
			selectUPPage();
			selectCurrentPage();
		}
		override public function destroyView():void
		{
			removeEvtListener();
			_upPage.destroyView();
			_upPage = null;
			
			_currPage.destroyView();
			_currPage= null;
			while(_currItemVec.length)
				_currItemVec.pop().destroyView();
			while(_preItemVec.length)
				_preItemVec.pop().destroyView();
			super.destroyView();
		}
		
	}
}